ChatController

The primary entry point for integrating the Genesys Cloud chat experience into a host application.

ChatController manages the lifecycle of a chat session, including starting, ending, reconnecting, and presenting the chat UI. The host application creates an instance from a configured MessengerAccount using Builder, and registers a ChatEventListener to receive lifecycle callbacks.

Prerequisites:

Usage:

val account = MessengerAccount(
deploymentId = "your-deployment-id",
domain = "your-domain.com"
).apply {
logging = true
sessionExpirationNoticeInterval = 300
}

val chatController = ChatController.Builder(context)
.chatEventListener(this)
.build(account, chatLoadedListener)

Important: Builder.build initiates the chat session and the chat UI Fragment is delivered via ChatLoadedListener.onComplete. Ensure the account is fully configured before calling it.

Types

Link copied to clipboard
class Builder

Builder for creating and configuring a ChatController instance.

Properties

Link copied to clipboard

The listener that receives state changes, errors, and chat elements, or null if none is registered.

Link copied to clipboard
open override val isActive: Boolean

Chat in progress

Link copied to clipboard
open override val isLiveChat: Boolean

Chat with agent

Link copied to clipboard

Indicates whether this controller has already been destroyed.

Functions

Link copied to clipboard
open override fun clearConversation()

Clears the current conversation history from the session.

Link copied to clipboard
open override fun destruct()

Destroys this controller and releases all associated resources.

Link copied to clipboard
open override fun endChat(forceClose: Boolean = false)

Ends the current chat session.

Link copied to clipboard

Returns true if ChatController has open chats

Link copied to clipboard
open override fun isEnabled(name: String, default: Boolean? = null, data: Any? = null): Boolean?

Returns name enalability value if recognized.

Link copied to clipboard
open override fun logoutFromAuthenticatedSession()

Logs out from the current authenticated session.

Link copied to clipboard
fun reauthorizeImplicitFlow(idToken: String, nonce: String)

Reauthorizes the implicit authentication flow with a new token after expiration.

Link copied to clipboard
open override fun reconnectChat()

Attempts to reconnect a disconnected chat session.

Link copied to clipboard
fun restoreChat(fragment: Fragment? = null, account: AccountInfo? = null)

Start new chat or Continue an open chat. Chat fragment can be provided by the app - as in case of restoring activity

Link copied to clipboard
open override fun startChat(accountInfo: AccountInfo)

Starts new chat with provided account. Configured as restorable, won't end on UI removal.

Link copied to clipboard

Terminates the active chat session and releases the underlying chat handler immediately.

Link copied to clipboard
open override fun updateCustomAttributes(customAttributes: Map<String, String>)

Updates the custom attributes associated with the current chat session.